package com.lee.demosharding.config;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/11/22
 */
public class MyPreciseShardingAlgorithm implements PreciseShardingAlgorithm<Long> {
    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Long> preciseShardingValue) {
        // customerId<1000 放入0号表, >=1000放入1号表
        String endChar = "";
        int compare = preciseShardingValue.getValue().compareTo(1000L);
        if (compare >= 0) {
            endChar = "bill_2";
        } else {
            endChar = "bill_1";
        }
        if (collection.contains(endChar)) {
            return endChar;
        }
        return null;
    }
}
